//
//  YWProgressView.m
//  Chinese
//
//  Created by yellow on 2021/3/8.
//  Copyright © 2021 YSLC. All rights reserved.
//

#import "YWProgressView.h"

@implementation YWProgressView



-(instancetype)init{
    if (self = [super init]) {
        
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}



-(void)setProgress:(CGFloat)progress{

    _progress = progress;

    [self setNeedsDisplay];

}


//-(void)drawRect:(CGRect)rect{
//
//    // 获取参数
//    CGPoint center = CGPointMake(rect.size.width * 0.5, rect.size.height * 0.5);
//    CGFloat radius = rect.size.width * 0.5  - 3;
//    CGFloat startAngle = -M_PI_2;
//    CGFloat endAngle = 2 * M_PI * self.progress + startAngle;
//
////    UIBezierPath *path = [[UIBezierPath alloc] init];
////    [path addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:true];
//
//
//    UIBezierPath  *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
//
//
//    [path addLineToPoint:center];
//    [path closePath];
//
//    [YWColorRGBA(1, 0, 1, 0.5) set];
//
//    [path fill];
//
//
//
//}


- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    
    //画弧
    //1.获取上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //2.描述路径
    CGPoint center = CGPointMake(rect.size.width * 0.5, rect.size.height * 0.5);
    CGFloat radius = rect.size.width * 0.5 - 3;
    CGFloat startA = -M_PI_2;
    CGFloat angle =  self.progress *  M_PI * 2;
    CGFloat endA = startA + angle;
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
    [path addLineToPoint:center];
    [otherMainColor set];
    
    //3.把路径添加到上下文当中
    CGContextAddPath(ctx, path.CGPath);
    //4.把上下文的内容渲染到View的layer上.
//    CGContextStrokePath(ctx);
    CGContextFillPath(ctx);

}
@end
